package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.POJO.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import java.util.List;

public interface UserMapper {
    @Select("select * from t_user where username = #{username}")
    User findUserByusername(String username);
    /*
       select * from t_user
       <where>
          <if test="queryString !=null and queryString.length > 0">
             username like concat('%',#{queryString},'%')
            </if>
       </where>
       */
    @Select("<script>" +
            "select * from t_user\n" +
            "        <where>\n" +
            "           <if test=\"queryString !=null and queryString.length > 0\">\n" +
            "              username like concat('%',#{queryString},'%')\n" +
            "             </if>\n" +
            "        </where>" +
            "</script>")
    Page<User> findPage(@Param("queryString") String queryString);



    @Insert("INSERT INTO t_user VALUES (#{birthday},#{gender},#{username},#{password},#{remark},#{station},#{telephone})")
    @SelectKey(keyProperty = "id",statement = "select last_insert_id();",resultType = int.class  ,before = false)
    void addUser(User user);

    @Insert("insert into t_user_role values (#{id},#{roleid})")
    void adduser_roleByuserID(@Param("id") Integer id,@Param("roleid") Integer roleid);

    @Select("SELECT username FROM t_user")
    List<User> findAllHealthManager();

}
